package com.hs.android.fortress.intro;

import com.hs.android.fortress.net.AsyncNetworking;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.util.Log;

public class RoomDialogFactory {

	public Activity mActivity;
	
	public RoomDialogFactory(Activity activity){
		mActivity = activity;
	}
	
	public AlertDialog create(String result){
		AlertDialog dialog = null;
		
		Log.d("result","EnterRoom result : " + result);
		
		if (result == null || result.equals("fail")) {
			dialog = AsyncNetworking.makeNetworkProblemDialog(mActivity)
				.setPositiveButton("OK", mPositiveListener)
				.create();
		} else if (result.equals("soFar")) {
			dialog = createExtraDialog("Fail : So Far");
		} else if (result.equals("playing")){
			dialog = createExtraDialog("Fail : playing state");
		}else if(result.equals("entered")){
			dialog = null;
		}
		
		return dialog;
	}
	
	private AlertDialog createExtraDialog(String message){
		return new AlertDialog.Builder(mActivity)
			.setTitle("Problem")
			.setMessage(message)
			.setCancelable(false)
			.setPositiveButton("OK", mPositiveListener)
			.create();
	}
	
	private OnClickListener mPositiveListener = new OnClickListener() {
		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			dialog.dismiss();
			mActivity.finish();
		}
	};
	
}
